home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / win_u_z / xlock_dv.zip / SOURCES.ZIP / XCRDYNCM.C < prev    next >
C/C++ Source or Header  |  1992-08-07  |  2KB  |  87 lines

  1. #ifndef lint
  2. static char sccsid[] = "@(#)XCrDynCmap.c 22.2 89/09/20";
  3. #endif
  4. /*-
  5.  * XCrDynCmap.c - X11 library routine to create dynamic colormaps.
  6.  *
  7.  * Copyright (c) 1989 by Sun Microsystems, Inc.
  8.  *
  9.  * Author: Patrick J. Naughton
  10.  * naughton@sun.com
  11.  *
  12.  * Permission to use, copy, modify, and distribute this software and its
  13.  * documentation for any purpose and without fee is hereby granted,
  14.  * provided that the above copyright notice appear in all copies and that
  15.  * both that copyright notice and this permission notice appear in
  16.  * supporting documentation.
  17.  *
  18.  * This file is provided AS IS with no warranties of any kind.  The author
  19.  * shall have no liability with respect to the infringement of copyrights,
  20.  * trade secrets or any patents by this file or any part thereof.  In no
  21.  * event will the author be liable for any lost revenue or profits or
  22.  * other special, indirect and consequential damages.
  23.  *
  24.  */
  25.  
  26. #include <X11/X.h>
  27. #include <X11/Xos.h>
  28. #include <X11/Xlib.h>
  29. #include <X11/Xutil.h>
  30.  
  31. Status
  32. XCreateDynamicColormap(dsp, screen, cmap, visual, colors,
  33.                count, red, green, blue)
  34.     Display    *dsp;
  35.     int        screen;
  36.     Colormap   *cmap;
  37.     Visual    **visual;
  38.     XColor     *colors;
  39.     int        count;
  40.     u_char     *red,
  41.            *green,
  42.            *blue;
  43. {
  44.     XVisualInfo vinfo;
  45.     int        pixels[256];
  46.     int        i,
  47.         ncolors,
  48.         planes;
  49.     unsigned long pmasks;
  50.     Status    allocReturn;
  51.  
  52.     planes = DisplayPlanes(dsp, screen);
  53.     if (XMatchVisualInfo(dsp, screen, planes, PseudoColor, &vinfo)) {
  54.  
  55.     *visual = vinfo.visual;
  56.     *cmap = XCreateColormap(dsp, RootWindow(dsp, screen),
  57.                 *visual, AllocNone);
  58.     ncolors = vinfo.colormap_size;
  59.  
  60.     if (count > ncolors)
  61.         return BadValue;
  62.  
  63.     allocReturn = XAllocColorCells(dsp, *cmap,
  64.                        False, &pmasks, 0,
  65.                        pixels, count);
  66.  
  67. /*    This should return Success, but it doesn't... Xlib bug?
  68.  *    (I'll ignore the return value for now...)
  69.  */
  70. #ifdef NOTDEF
  71.     if (allocReturn != Success)
  72.         return allocReturn;
  73. #endif                /* NOTDEF */
  74.  
  75.     for (i = 0; i < count; i++) {
  76.         colors[i].pixel = pixels[i];
  77.         colors[i].red = *red++ << 8;
  78.         colors[i].green = *green++ << 8;
  79.         colors[i].blue = *blue++ << 8;
  80.         colors[i].flags = DoRed | DoGreen | DoBlue;
  81.     }
  82.     XStoreColors(dsp, *cmap, colors, count);
  83.     return Success;
  84.     } else
  85.     return BadMatch;
  86. }
  87.